package com.zs.infrastructure.util.basic;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @description: 线程池管理工具类
 * @author: wzc
 * @createDate: 2021/8/13 20:54
 */
@Component
public class ThreadPoolUtil {

    // 线程池，corePoolSize设置为cup的两倍
    private static ThreadPoolExecutor threadPoolExecutor;

    public static ThreadPoolExecutor threadPoolExecutor() {
        return threadPoolExecutor;
    }

    @PostConstruct
    public void init() {
        // 线程池，corePoolSize设置为cup的两倍
        threadPoolExecutor = new ThreadPoolExecutor(
                8,
                32,
                60L,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(100),
                new ThreadPoolExecutor.CallerRunsPolicy()
        );
    }

}
